package com.cskaoyan._03ex;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/2 16:14
 **/
/*
斐波那契数列

1, 1 , 2 , 3 , 5 , 8 , 13 , 21.....

求第n个位置的值是多少
f(1) = 1
f(2) = 1
f(3) = 1 + 1 = 2 = f(1) + f(2)
f(4) = 1+ 2 = 3 = f(2) + f(3)
...
f(n) = f(n-2) + f(n-1)
 */
public class Demo {
    public static void main(String[] args) {
        int value = getFeibonacci(6);
        System.out.println("value = " + value);
    }

    // 求第n个位置的值
    public static int getFeibonacci(int n) {
        // 递归出口
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 1;
        }
        // 递归体
        // f(n) = f(n-2) + f(n-1)
        return getFeibonacci(n - 2) + getFeibonacci(n - 1);
    }
}
